package model

import (
	"encoding/json"
	"github.com/doujunyu/gogo/gogo_log"
)

//申请成为好友表

const TableByChatApplyFriendGroup = "self_chat_apply_friend_group"

const ChatApplyFriendGroupByTypeIdFriend = 1//申请加好友
const ChatApplyFriendGroupByTypeIdGroup = 2//申请加入群
const ChatApplyFriendGroupByTypeIdGroupReverse = 3//群邀请用户

const ChatApplyFriendGroupByStatusWaiting = 0
const ChatApplyFriendGroupByStatusAgree = 1
const ChatApplyFriendGroupByStatusRefused = 2

type mergeUserIdByOnly struct {
	UserId interface{} `json:"user_id"`
}

// ChatApplyFriendGroupByMergeUserIdsToJson merge_user_ids 组合成json数据
func ChatApplyFriendGroupByMergeUserIdsToJson(userIds ...interface{})string{
	datas := make([]mergeUserIdByOnly,0)
	for _, v := range userIds {
		data := mergeUserIdByOnly{
			UserId: v.(interface{}),
		}
		datas = append(datas,data)
	}
	str ,err := json.Marshal(datas)
	if err != nil {
		gogo_log.Error("model_ChatApplyFriendGroupByMergeUserIdsToJson", "数据转json失败", err.Error())
		return ""
	}
	return string(str)
}

// ChatApplyFriendGroupByIsMergeUserIds 检测是否可以操作当前数据
func ChatApplyFriendGroupByIsMergeUserIds(jsonData string,userId int64)bool{
	var checkUserData []map[string]interface{}
	_ = json.Unmarshal([]byte(jsonData),&checkUserData)
	for _, datum := range checkUserData {
		if int64(datum["user_id"].(float64)) == userId {
			return true
		}
	}
	return false
}

